#include <iostream>
#include <unordered_map>
#include <queue>
using namespace std;

struct elementPair {
    pair<string, int> element;
    public : elementPair(pair<string, int> element) {
        this->element = element;
    }
    friend bool operator<(elementPair eleA, elementPair eleB) {
        return eleA.element.first > eleB.element.first;
    }
};

int main() {
    string chemMaterial;
    cin >> chemMaterial;
    unordered_map<string, int> eleMap;
    string currElement = "";
    int counter = 0;
    for (int i = 0; i <= chemMaterial.size(); i++) {
        if (i == chemMaterial.size()) {
            if (currElement.size() > 0) { eleMap[currElement] += counter == 0 ? 1 : counter; }
        }
        else {
            if ((int)chemMaterial[i] >= 65 && (int)chemMaterial[i] <= 90) {
                if (currElement.size() > 0) {
                    eleMap[currElement] += counter == 0 ? 1 : counter;
                    counter = 0;
                    currElement = "";
                    currElement += chemMaterial[i];
                }
                else {
                    currElement += chemMaterial[i];
                }
            }
            else if ((int)chemMaterial[i] >= 97 && (int)chemMaterial[i] <= 122) {
                currElement += chemMaterial[i];
            }
            else if ((int)chemMaterial[i] >= 48 && (int)chemMaterial[i] <= 57) {
                counter *= 10;
                counter += (int)chemMaterial[i] - 48;
            }
        }
    }
    priority_queue<elementPair> eleHeap;
    // 统计化学元素
    for (pair<string, int> elePair : eleMap) {
        eleHeap.push(elementPair(elePair));
    }
    while (!eleHeap.empty()) {
        elementPair elePair = eleHeap.top();
        eleHeap.pop();
        cout << elePair.element.first << " " << elePair.element.second << endl;
    }
    // 输出
    return 0;
    // 本题使用了哈希表和优先队列，适合熟悉C++数据结构
}